<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        table {
            border: 1px solid #e0e0e0;
            border-collapse: collapse;
        }

        td {
            border: 1px solid #e0e0e0;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav main-header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            容器入库业务
        </div>
    </header>
    <div class="aui-bar aui-bar-nav sub-header"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;padding-bottom: 50px;">
        <div class="white_background">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">业务类型</div>
                        <div class="aui-list-item-input">
                            <select id="businessType" onchange="onChangeBusiness()">
                            </select>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">子业务类型</div>
                        <div class="aui-list-item-input">
                            <select id="subBusinessType">
                            </select>
                        </div>
                    </div>
                </li>
                <li id="projectFlag" class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">受益项目</div>
                        <div class="aui-list-item-input">
                            <select id="project">
                            </select>
                        </div>
                    </div>
                </li>
                <li id="lydeptFlag" class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">项目</div>
                        <div class="aui-list-item-input">
                            <select id="proje">
                            </select>
                        </div>
                    </div>
                </li>
                <li id="sydeptFlag" class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">受益部门</div>
                        <div class="aui-list-item-input">
                            <select id="sydept">
                            </select>
                        </div>
                    </div>
                </li>

                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">仓库</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择/扫描 仓库" id="workCenterCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenter()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">库位</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择/扫描 库位" id="workCellCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">容器</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请扫描容器条码" id="traynum" value="" onclick="getIdSelector();">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">物料号</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择物料" id="mrlCode" value="" onclick="getIdSelector();"
                                disabled onfocus="focusFn(this)">
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrl()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">批次号</div>
                        <div class="aui-list-item-input">
                            <input type="number" id="lotCode">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">入库数量</div>
                        <div class="aui-list-item-input">
                            <input type="number" id="qty">
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="addTable()">新增</div>
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin-top:2%;" onclick="save()" id="submitButton">保存
        </div>
        <div class="white_background">
            <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:2%;"
                id="tbodyHtml">
            </div>


            <div class="table-responsive" id="appStorage" style="overflow-y:auto;height: 10rem;">
                <table id="tableS" class="table table-bordered " style="table-layout: fixed;">
                    <thead>
                        <tr id="tr1"
                            style="text-align: center;color: #757575;font-family: 微软雅黑;font-size: 12px;font-weight: bold;">
                            <td style="width:200px;">物料号</td>
                            <td style="width:200px;">规格</td>
                            <td style="width:200px;">物料名称</td>
                            <td style="width:120px;">批次号</td>
                            <td style="width:80px;">数量</td>
                            <td style="width:80px;">操作</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtmlAdd"
                        style='text-align: center;color: black;font-size: 11px;'>


                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var workCenterGid = ""; //仓库GID
    var workCenterCode = ""; //仓库编码
    var workCenterName = ""; //仓库名称
    var workCellGid = ""; //库位GID
    var workCellCode = ""; //库位编码
    var workCellName = ""; //库位名称
    var mrlCode = "";//物料编码
    var mrlName = "";//物料名称

    var scanRule = ""; //条码解析规则

    var code; //菜单路由参数
    var codesub; //菜单路由参数
    var workcenter; //菜单路由参数
    var workcell; //菜单路由参数
    var centerClass; //菜单路由参数
    var titleTxt;
    var sydeptFlag;
    var syprojectFlag;
    var lydeptFlag;

    var drawingN = ""
    var arrSave = []
    //初始化查询仓库下拉框
    apiready = function () {

        $("#workCenterCode").focus();
        idSelector = "workCenterCode";

        //菜单参数
        var query = api.pageParam.query;
        code = query.code
        codesub = query.codesub
        workcenter = query.workcenter;
        workcell = query.workcell;
        titleTxt = query.titleTxt;
        sydeptFlag = query.sydeptFlag;
        syprojectFlag = query.syprojectFlag;
        lydeptFlag = query.lydeptFlag;

        console.log('子业务类型：' + codesub)

        if (titleTxt != undefined && titleTxt != null && titleTxt != "") {
            document.getElementById("title").innerHTML = titleTxt;
        }
        var centerDis = query.centerDis;
        var cellDis = query.cellDis;
        var businessTypeDisable = query.typeDisable;//是否禁用业务类型和子业务类型
        if (businessTypeDisable != undefined && businessTypeDisable != null && businessTypeDisable == "Y") {
            $("#businessType").attr('disabled', true);
            $("#subBusinessType").attr('disabled', true);
        }
        if (centerDis != undefined && centerDis != null && centerDis == "Y") {
            $("#workCenterCode").attr('disabled', true);
            //设置仓库选择点击事件无效
            document.getElementById("centerSelect").onclick = function () { };
        }
        if (cellDis != undefined && cellDis != null && cellDis == "Y") {
            $("#workCellCode").attr('disabled', true);
            //设置库位选择点击事件无效
            document.getElementById("cellSelect").onclick = function () { };
        }
        if (workcenter != undefined && workcenter != null && workcenter != "") {
            $("#workCenterCode").focus();
            idSelector = "workCenterCode";
            getWorkCenter(workcenter, idSelector);
        }
        if (workcell != undefined && workcell != null && workcell != "") {
            $("#workCellCode").focus();
            idSelector = "workCellCode";
            getWorkCenter(workcell, idSelector);
        }
        if (sydeptFlag === "Y") {
            document.getElementById("sydeptFlag").style.display = "none";
        }
        if (syprojectFlag === "Y") {
            document.getElementById("projectFlag").style.display = "none";
        }
        if (lydeptFlag === "Y") {
            document.getElementById("lydeptFlag").style.display = "none";
        }




        //查询业务类型下拉框
        doSearchBusinessType();
        doSearchLyDept();
        doSearchSyDept();
        doSearchProject();
    }



    //业务类型下拉框
    function doSearchBusinessType() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getBusinessType";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                type: 'IN',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("businessType"), html);
                $("#businessType").val(code);
                onChangeBusiness();
            }
        });
    }

    //部门下拉框
    function doSearchLyDept() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getProject";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                subBussinessType: codesub,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("proje"), html);
                $("#proje").val(code);
            }
        });
    }

    //部门下拉框
    function doSearchSyDept() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getSyDept";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                subBussinessType: codesub,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("sydept"), html);
                $("#sydept").val(code);
            }
        });
    }

    //部门下拉框
    function doSearchProject() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getProject";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                subBussinessType: codesub,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("project"), html);
                $("#project").val(code);
            }
        });
    }

    //业务类型下拉框值改变
    function onChangeBusiness() {
        var businessType = $("#businessType").val();
        //源仓库不为空，查询库位下拉框
        if (businessType != "" && businessType != null && businessType != undefined) {
            var serverUrl = localStorage.getItem('serverUrl');
            var un = localStorage.getItem('un');
            var url = serverUrl + "/app/getSubBusinessType";
            var data = {
                values: { ////以表单方式提交参数（JSON对象）
                    type: 'IN',
                    businessType: businessType,
                    un: un
                }
            };
            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 300,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var map = eval("(" + data + ")");
                    var list = eval(map.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                    }
                    $api.html($api.byId("subBusinessType"), html);
                    $("#subBusinessType").val(codesub);
                }
            });
        } else {
            $api.html($api.byId("subBusinessType"), "");
        }

        $("#traynum").focus();
        idSelector = "traynum";
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //alert(ret);扫码的结果都是编码
            //1：仓库
            if (idSelector == 'workCenterCode') {

                $("#workCenterCode").val(ret);
                //查询仓库
                getWorkCenter(ret, idSelector);

                //2:库位
            } else if (idSelector == 'workCellCode') {

                $("#workCellCode").val(ret);
                //查询库位
                getWorkCell(ret, idSelector);

                //扫描容器
            } else if (idSelector == 'traynum') {
                //查询托下的箱信息显示
                $("#traynum").val(ret);
                getBoxInfoByTray(ret, 1);
            }
        });
    }

    //1：仓库扫描校验
    function getWorkCenter(code, inputId) {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getWorkCenter";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterCode: code,
                mrlCode: "",
                lotCode: "",
                qty: "",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCenterGid = list[0].workCenterGid;
                    workCenterCode = list[0].workCenterCode;
                    workCenterName = list[0].workCenterName;
                    document.getElementById(inputId).value = workCenterCode + ":" + workCenterName;
                    $("#workCellCode").focus();
                    idSelector = "workCellCode";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCenterCode").focus();
                    $("#workCenterCode").select();
                }
            }
        });
    }

    //2：选择仓库
    function goSelectWorkCenter() {
        api.openWin({
            name: 'uwmSelectWorkCenter',
            url: 'uwmSelectWorkCenter.html',
            pageParam: {
                flag: "in",
                name: "uwmInOfStockByTrayVesselNew_cpbfrk",
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        });
    }

    //仓库选择后回调函数
    function setWorkCenter(id, code, name) {
        workCenterGid = id;
        workCenterCode = code;
        workCenterName = name;
        //$("#workCenterCode").attr("value",code+":"+name);
        document.getElementById('workCenterCode').value = code + ":" + name;
        $("#workCellCode").focus();
        idSelector = "workCellCode";
    }

    //3；PDA自带扫描回车事件
    $("#workCenterCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCenterCode").val(sm);
            // console.log("扫描回车事件：" + sm);
            //校验改箱码是否存在
            getWorkCenter(sm, "workCenterCode");
        }
    });

    //选择物料
    function goSelectMrl() {
        api.openWin({
            name: 'usmSelectMrl',
            url: 'usmSelectMrl.html',
            pageParam: {
                name: "uwmInOfStockByTrayVesselNew_cpbfrk",
            }
        });
    }

    //物料选择后回调函数
    function setMrl(sysid, code, name, drawing) {
        $("#mrlCode").val(code + ":" + name + ":" + drawing);
        mrlCode = code;
        mrlName = name;
        drawingN = drawing;
    }

    //5:库位扫描校验
    function getWorkCell(code, inputId) {
        //扫库位前先扫仓库
        if (inputId == "workCellCode") {
            if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
                api.toast({
                    msg: "请先选择/扫描 仓库",
                    duration: 3000
                });
                $("#workCellCode").val("");
                workCellCode = "";
                workCellGid = "";
                workCellName = "";
                return;
            }
        }
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCenterByCell";
        var data = {
            values: {
                flag: "in_rk", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: workCenterGid, //仓库GID
                workCellCode: code, //库位编码
                workCellGid: workCellGid,
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "", //原库位调入库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCellGid = list[0].cellid;
                    workCellCode = list[0].cellcode;
                    workCellName = list[0].cellname;
                    // workCenterCode = list[0].code;
                    // workCenterGid = list[0].id;
                    // workCenterName = list[0].name;
                    // document.getElementById("workCenterCode").value = workCenterCode + ":" + workCenterName;
                    document.getElementById(inputId).value = workCellCode + ":" + workCellName;
                    $("#traynum").focus();
                    idSelector = "traynum";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCellCode").focus();
                    $("#workCellCode").select();
                }
            }
        });
    }

    //6：选择库位
    function goSelectWorkCell() {
        var tm = $("#tm").val();
        //仓库非空校验
        if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
            api.toast({
                msg: "请先选择/扫描 仓库",
                duration: 3000
            });
            return;
        }

        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "in_rk",
                name: "uwmInOfStockByTrayVesselNew_cpbfrk",
                tm: tm,
                workCenterGid: workCenterGid,
                relWorkCellGid: "",
                workCellFlag: ""
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name) {
        workCellGid = id;
        workCellCode = code;
        workCellName = name;
        document.getElementById('workCellCode').value = code + ":" + name;
        getWorkCell(workCellCode, "workCellCode")
        $("#boxnum").focus();
        var e = "boxnum";
        idSelector = e;
    }

    //7；PDA自带扫描回车事件-库位
    $("#workCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCellCode").val(sm);
            //校验改箱码是否存在
            getWorkCell(sm, "workCellCode");
        }
    });

    //查询托下的箱信息展示 flag=1 为初始扫描容器获取箱信息，不显示库转结果、库转信息列，
    //flag=2 为库转保存后返回显示，需要显示库转结果、库转信息列
    function getBoxInfoByTray(traynum, flag) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getBoxInfoByTrayVessel";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: {
                traynum: traynum,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = myobj.list;
                    var centerGid = myobj.workCenterGid;
                    var centerName = myobj.workCenterName;
                    var centerCode = myobj.workCenterCode;
                    var cellGid = myobj.workCellGid;
                    var cellCode = myobj.workCellCode;
                    var cellName = myobj.workCellName;

                    var html = "";
                    // if (list.length > 0) {
                    //     api.toast({
                    //         msg: "容器已绑定物料！",
                    //         duration: 3000
                    //     });
                    //     return;

                    // }

                    //遍历
                    for (var i = 0; i < list.length; i++) {

                        html += "<div id = '" + list[i].mrlCode + "' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 120px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<table style='width:100%;'>";
                        if (list[i].mrlCode == undefined) {
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料编码：</td><td  id='mrlCodetital' ' colspan='2'>" + "" + "</td></tr>";
                        } else {
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料编码：</td><td  id='mrlCodetital' ' colspan='2'>" + list[i].mrlCode + "</td></tr>";
                        }

                        if (list[i].mrlName == undefined) {
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料名称：</td> <td  id='mrlNametital' ' colspan='3'>" + "" + "</td></tr>";
                        } else {
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料名称：</td> <td  id='mrlNametital' ' colspan='3'>" + list[i].mrlName + "</td></tr>";
                        }
                        if (list[i].ext05 == undefined) {
                            html += "<tr style='width:100%;'><td style='width:30%;'>批次号：</td> <td  id='lotCodetital' ' colspan='3'>" + "" + "</td></tr>";
                        } else {
                            html += "<tr style='width:100%;'><td style='width:30%;'>批次号：</td><td id='lotCodetital' ' >" + list[i].ext05 + "</td></tr>";
                        }
                        html += "<tr style='width:100%;'><td style='width:15%;'>数量：</td><td id='qtytital' >" + list[i].qty + "</td></tr>";
                        html += "</table></div>";
                    }
                    // if (flag == 1) {
                    //     $("#workCenterCode").val(workCenterName);
                    //     $("#workCellCode").val(workCellName);
                    // }
                    // if(cellGid!=''){
                    //     workCenterGid=centerGid;
                    //     workCenterName=centerName;
                    //     workCenterCode=centerCode;
                    //     workCellGid=cellGid;
                    //     workCellCode=cellCode;
                    //     workCellName=cellName;
                    //     document.getElementById("workCenterCode").value = workCenterCode + ":" + workCenterName;
                    // document.getElementById("workCellCode").value = workCellCode + ":" + workCellName;
                    // }

                    $api.html($api.byId("tbodyHtml"), html);
                } else if (myobj.code == '1') {
                    $("#traynum").val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        })




    }

    //保存按钮
    function save() {
        if (!clickThrottle()) {
            return;
        }
        //业务类型
        var businessType = $("#businessType").val();
        //子业务类型
        var subBusinessType = $("#subBusinessType").val();

        //数量
        var qty = $("#qty").val();
        //容器
        var traynum = $("#traynum").val();

        var proje = $("#proje").val();
        var sydept = $("#sydept").val();
        var project = $("#project").val();

        var lotCode = $("#lotCode").val();

        var listNew = JSON.stringify(arrSave)
        const submitButton = document.getElementById('submitButton');

        submitButton.style.pointerEvents = "none"
        //业务类型非空校验
        if (businessType == "" || businessType == null || businessType == undefined) {
            api.toast({
                msg: '请选择业务类型',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        /* if (syprojectFlag != "Y") {
            if (project == "" || project == null || project == undefined) {
                api.toast({
                    msg: '请选择受益项目',
                    duration: 3000
                });
                submitButton.style.pointerEvents = "auto"
                return;
            }
        }
        if (lydeptFlag != "Y") {
            if (proje == "" || proje == null || proje == undefined) {
                api.toast({
                    msg: '请选择项目',
                    duration: 3000
                });
                submitButton.style.pointerEvents = "auto"
                return;
            }
        }
        if (sydeptFlag != "Y") {
            if (sydept == "" || sydept == null || sydept == undefined) {
                api.toast({
                    msg: '请选择受益部门',
                    duration: 3000
                });
                submitButton.style.pointerEvents = "auto"
                return;
            }
        } */
        //仓库非空校验
        if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
            api.toast({
                msg: '请选择/扫描仓库',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        //库位非空校验
        if (workCellGid == "" || workCellGid == null || workCellGid == undefined) {
            api.toast({
                msg: '请选择/扫描库位',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        //容器非空校验
        if (traynum == "" || traynum == null || traynum == undefined) {
            api.toast({
                msg: '容器不能为空',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        api.showProgress({
            title: '保存中...',
        });

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uwmInOfStockByTraySaveVesselNewCp";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                businessType: businessType, //业务类型
                subBusinessType: subBusinessType, // 子业务类型
                //mrlCode: mrlCode,
                //mrlName: mrlName,
                workCenterGid: workCenterGid, //仓库id
                workCellGid: workCellGid, //库位id
                workCenterCode: workCenterCode, //仓库编码
                workCellCode: workCellCode, //库位编码
                workCenterName: workCenterName, //仓库名
                workCellName: workCellName, //库位名
                proje: proje,
                project: project,
                sydept: sydept,
                traynum: traynum, //容器码
                list: JSON.stringify(arrSave),
                //lotCode: lotCode,
                //qty: qty,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    //getBoxInfoByTray(traynum, 2);

                    $api.html($api.byId("tbodyHtmlAdd"), "");

                    $("#traynum").focus();
                    idSelector = "traynum";
                    $("#traynum").val("");
                    $("#mrlCode").val("");
                    $("#lotCode").val("");
                    $("#qty").val("");
                    arrSave = []
                    $("#message").html(myobj.message);
                } else if (myobj.code == '1') {
                    //$("#traynum").val("");
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    $("#traynum").select();
                    //getBoxInfoByTray(traynum, 2, myobj.code);
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                submitButton.style.pointerEvents = "auto"
            }
        });


    }

    //箱号监听回车事件
    $("#traynum").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                console.log(tm);
                $("#traynum").blur();
                getBoxInfoByTray(tm, 1);
            }
        }
    });

    function addTable() {
        var lotCode = $("#lotCode").val()
        var qty = $("#qty").val()
        //批次号非空校验
        if (mrlCode == "" || mrlCode == null || mrlCode == undefined) {
            api.toast({
                msg: '物料号不能为空',
                duration: 3000
            });
            return;
        }
        //批次号非空校验
        if (lotCode == "" || lotCode == null || lotCode == undefined) {
            api.toast({
                msg: '批次号不能为空',
                duration: 3000
            });
            return;
        }

        //数量非空校验
        if (qty == "" || qty == null || qty == undefined) {
            api.toast({
                msg: '数量不能为空',
                duration: 3000
            });
            return;
        } else {
            if (parseInt(qty) <= 0) {
                api.toast({
                    msg: '数量必须大于0',
                    duration: 3000
                });
                return;
            }
        }
        for (var i = 0; i < arrSave.length; i++) {
            if (arrSave[i].mrlCode == mrlCode) {
                if (arrSave[i].lotCode == lotCode) {
                    api.toast({
                        msg: '已存在相同物料相同批次，无法新增！',
                        duration: 3000
                    });
                    return;
                }
            }
        }
        var model = {
            mrlCode: mrlCode, //物料号
            drawing: drawingN,
            mrlName: mrlName, //物料号
            lotCode: lotCode, //批次号
            qty: qty, //转移数量
        }
        arrSave.push(model);
        setTable(arrSave)
    }
    function setTable(arrSave) {
        var html = "";

        $("#lotCode").val("")
        $("#mrlCode").val("")
        $("#qty").val("")
        if (arrSave.length > 0) {
            for (var i = 0; i < arrSave.length; i++) {
                html += "<tr style='text-align: center;color: black;font-size: 11px;' >";
                html += "<td name='mrlCode'>" + arrSave[i].mrlCode + "</td>";
                html += "<td name='mrlCode'>" + arrSave[i].drawing + "</td>";
                html += "<td name='mrlName'>" + arrSave[i].mrlName + "</td>";
                html += "<td name='lotCode'>" + arrSave[i].lotCode + "</td>";
                html += "<td name='qty'>" + arrSave[i].qty + "</td>";
                html += "<td><a onclick='deleteBtn(\"" + arrSave[i].mrlCode + "\",\"" + arrSave[i].lotCode + "\")' >删除</a></td>"
                html += "</tr>";
            }
            $api.html($api.byId("tbodyHtmlAdd"), html);

        } else {
            $api.html($api.byId("tbodyHtmlAdd"), "");
        }
    }
    function deleteBtn(mrlCode, lotCode) {
        for (var i = 0; i < arrSave.length; i++) {
            if (arrSave[i].mrlCode == mrlCode) {
                if (arrSave[i].lotCode == lotCode) {
                    arrSave.splice(i, 1)
                }
            }
        }
        setTable(arrSave)
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>